﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cosmetic.Logic;
using Cosmetic.DataEntity;

namespace WebApp.Space.AccountInfo
{
    public partial class Welcome : PageBase
    {
        PurchaseManager m_PurchaseManager = new PurchaseManager();
        private UserManager m_UserManager = new UserManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.SignInUser == null)
            {
                Page.RegisterClientScriptBlock("key", "<script>window.top.location = '/Login.aspx';</script>");
                return;
            }
            if (!IsPostBack)
            {
                this.ltlUserName.Text = this.SignInUser.UserName;//用户名.
                ltlIntegral.Text = this.SignInUser.Integral.ToString();

                List<Order> theOrderList = m_PurchaseManager.GetOrdersByUser_rh(this.SignInUser); //这是该用户所有的订单记录。
                int orderCount = 0; //多少张订单。
                int orderCountDone = 0;//已成交订单数。
                decimal money1 = 0;//累计消费金额,包含“完成”和“已发送”两种状态。
                decimal money2 = 0;//累计成交订单总金额
                orderCount = theOrderList.Count;

                //for (int i = 0; i < theOrderList.Count; i++)
                //{
                //    if (theOrderList[i].State == "完成")
                //    {
                //        orderCountDone++;
                //        money2 += theOrderList[i].Price.Value;
                //        money1 += theOrderList[i].Price.Value;
                //    }
                //    if (theOrderList[i].出货发送 == "已发送")
                //    {
                //        money1 += theOrderList[i].Price.Value;
                //    }
                //}

                //this.LabelOrderCount.Text = orderCount.ToString();
                //this.LabelOrderSuccessful.Text = orderCountDone.ToString();
                //this.LabelAllMoney.Text = money1.ToString();
                //this.LabelSuccessMoney.Text = money2.ToString();
                //BindListView(theOrderList);

                this.rptOrderList.DataSource = theOrderList.OrderByDescending(c=>c.CreateTime).Take(4);
                this.rptOrderList.DataBind();
                //BindOrder(System.DateTime.Now.AddDays(-7));
            }
        }

        public string GetUserNameById(string UserId)
        {
            return m_UserManager.GetUserById(new Guid(UserId)).UserName;
        }
    }
}